package com.learn.project2.controller.admin;

import com.learn.project2.bean.MarketOrder;
import com.learn.project2.bean.MarketOrderChannel;
import com.learn.project2.config.customException.ShipException;
import com.learn.project2.model.bo.admin.order.OrderListBO;
import com.learn.project2.model.bo.admin.order.OrderRefundBO;
import com.learn.project2.model.bo.admin.order.OrderReplyBO;
import com.learn.project2.model.bo.admin.order.OrderShipBO;
import com.learn.project2.model.vo.admin.order.OrderDetailVO;
import com.learn.project2.model.vo.admin.order.OrderListVO;
import com.learn.project2.service.admin.order.OrderService;
import com.learn.project2.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author 王力
 * @date 2022-01-06 21:37
 * @version 1.0
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * @description: 订单管理-查询
     * @param: [orderListBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 15:49:55
     */
    @RequestMapping("list")
    @RequiresPermissions(value = "admin:order:list")
    public Result list(OrderListBO orderListBO){
        OrderListVO orderListVO = orderService.orderList(orderListBO);
        return Result.ok(orderListVO);
    }

    /**
     * @description: 订单管理-详情
     * @param: [id]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 17:42:08
     */
    @RequestMapping("detail")
    @RequiresPermissions("admin:order:read")
    public Result detail(Integer id){
        OrderDetailVO detailVO = orderService.orderDetail(id);
        return Result.ok(detailVO);
    }

    /**
     * @description: 订单-渠道查询
     * @param: []
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-11 15:06:18
     */
    @RequestMapping("channel")
    public Result channel(){
        List<MarketOrderChannel> channelVOS = orderService.orderChannel();
        return Result.ok(channelVOS);
    }


    /**
     * @description: 订单退款
     * @param: [refundBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-11 16:38:26
     */
    @RequestMapping("refund")
    @RequiresPermissions("admin:order:refund")
    public Result refund(OrderRefundBO refundBO){
        Integer code = orderService.orderRefund(refundBO);
        return Result.ok();
    }


    /**
     * @description: 订单管理-删除
     * @param: [orderId]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-07 17:30:50
     */
    /** 
     * @description:
     * @param: 请求参数修改 
     * @return:
     * @author zhizhuke
     * @date: 2022-01-09 16:10
     */ 
    @RequestMapping("delete")
    @RequiresPermissions("admin:order:delete")
    public Result delete(@RequestBody Map map, HttpServletRequest request){
        Integer orderId = (Integer) map.get("orderId");
        int code =  orderService.orderDelete(orderId);
        return Result.ok();
    }
    

    /** 
     * @description: 订单管理-发货
     * @param: [orderShipBO] 
     * @return: com.learn.project2.utils.Result 
     * @author 王力
     * @date: 2022-01-07 17:23:53
     */ 
    @RequestMapping("ship")
    @RequiresPermissions("admin:order:ship")
    public Result ship(@RequestBody OrderShipBO orderShipBO) throws ShipException {
        Integer code = orderService.orderShip(orderShipBO);
        return Result.ok();
    }
    
    /**
     * @description: 商品管理-商品评论-回复
     * @param: [replyBO]
     * @return: com.learn.project2.utils.Result
     * @author 王力
     * @date: 2022-01-08 14:08:11
     */
    @RequestMapping("reply")
    @RequiresPermissions("admin:order:reply")
    public Result reply(@RequestBody OrderReplyBO replyBO){
        Integer code = orderService.orderReply(replyBO);
        return Result.ok();
    }



}
